<ui:composition template="/pages/templates/layout.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="title">Enregistrement des contrats</ui:define>
	<ui:define name="content">
		<h:form id="form">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />

			<p:panel id="toggleable" styleClass="toUpdate"  header="ENREGISTREMENT DES CONTRATS"
				toggleable="true" toggleSpeed="500" widgetVar="panel">
				<p:fieldset id="saisie" legend="Saisie des informations"
					toggleable="true" toggleSpeed="500">
					<h:panelGrid columns="3" cellpadding="10">

						<p:outputLabel for="journaliste" value="Journaliste"
							styleClass="label" />
						<p:selectOneMenu id="journaliste" required="true"
							value="#{journalisteJournalBean.selectedJournalisteCombo}"
							converter="omnifaces.SelectItemsConverter">
							<f:selectItem itemLabel="Selectionnez" noSelectionOption="true" />
							<f:selectItems var="journalist"
								value="#{journalisteJournalBean.journalistes}"
								itemLabel="#{journalist.journalisteNom}"
								itemValue="#{journalist}" />
							<p:ajax update="journalisteMsg" event="keyup" />
						</p:selectOneMenu>
						<p:message id="journalisteMsg" for="journaliste" display="icon" />


						<p:outputLabel for="journal" value="Journal" styleClass="label" />
						<p:selectOneMenu id="journal" required="true"
							value="#{journalisteJournalBean.selectedJournalCombo}"
							converter="omnifaces.SelectItemsConverter">
							<f:selectItem itemLabel="Selectionnez" itemValue="#{null}" noSelectionOption="true" />
							<f:selectItems var="journal"
								value="#{journalisteJournalBean.journals}"
								itemLabel="#{journal.journalTitre}" />
							<p:ajax update="journalMsg" event="keyup" />
						</p:selectOneMenu>
						<p:message id="journalMsg" for="journal" display="icon" />

						<p:outputLabel for="date" value="Date du contrat" />
						<p:calendar id="date"
							value="#{journalisteJournalBean.currentJournalisteJournal.jrlteJnalDate}"
							locale="fr" navigator="true" showButtonPanel="true"
							required="true" pattern="dd/MM/yyyy">
							<p:ajax update="dateMsg" event="keyup" />
						</p:calendar>
						<p:message id="dateMsg" for="date" display="icon" />
					</h:panelGrid>

					<p:separator />

					<p:commandButton value="Enrégistrer"
						binding="#{journalisteJournalBean.btnSave}"
						action="#{journalisteJournalBean.saveJournalisteJournal}"
						icon="ui-icon-disk" update="@all">
						<p:confirm header="Confirmation"
							message="Voulez-vous enrégistrer ?" icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Modifier"
						binding="#{journalisteJournalBean.btnUpdate}"
						action="#{journalisteJournalBean.updateJournalisteJournal}"
						icon="ui-icon-refresh" update="@all" disabled="true">
						<p:confirm header="Confirmation" message="Voulez-vous modifier ?"
							icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Supprimer"
						binding="#{journalisteJournalBean.btnDelete}"
						action="#{journalisteJournalBean.deleteJournalisteJournal}"
						icon="ui-icon-trash" update="@all" disabled="true">
						<p:confirm header="Confirmation" message="Voulez-vous supprimer ?"
							icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Annuler"
						action="#{journalisteJournalBean.resetField}"
						icon="ui-icon-cancel" update=":form:saisie" />

					<p:confirmDialog global="true" showEffect="puff"
						hideEffect="explode">
						<p:commandButton value="Oui" type="button"
							styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
						<p:commandButton value="Non" type="button"
							styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
					</p:confirmDialog>
				</p:fieldset>
</p:panel>
				<p:dataTable id="table" var="contrat" 
					value="#{journalisteJournalBean.journalisteJournals}"
					selection="#{journalisteJournalBean.selectedJournalisteJournal}"
					selectionMode="single" rowKey="#{contrat.id}"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					paginator="true" rows="10" rowsPerPageTemplate="5,10,15"
					styleClass="table">
					<p:ajax event="rowSelect"
						listener="#{journalisteJournalBean.updateField}"
						update="@(.toUpdate)" />

					<p:column headerText="Journalistes" styleClass="column">
						<h:outputText value="#{contrat.journaliste.journalisteNom}" />
					</p:column>

					<p:column headerText="Journals" styleClass="column">
						<h:outputText value="#{contrat.journal.journalTitre}" />
					</p:column>

					<p:column headerText="Dates" styleClass="column">
						<h:outputText value="#{contrat.jrlteJnalDate}">
							<f:convertDateTime pattern="dd-MM-yyyy" />
						</h:outputText>
					</p:column>
				</p:dataTable>
		
		</h:form>
	</ui:define>
</ui:composition>
